package com.study.common

import android.widget.ListView

object ListViewUtil {
    fun setHeight(listView: ListView) {
        val adapter = listView.adapter ?: return
        var height = 0
        for (i in 0 until adapter.count) {
            val view = adapter.getView(i, null, listView)
            view.measure(0, 0)
            height += view.measuredHeight
        }
        val params = listView.layoutParams
        params.height = height + (adapter.count - 1) * listView.dividerHeight
        listView.layoutParams = params
    }
}
